﻿using Microsoft.Extensions.Configuration;

namespace xu.TinyDBConfigProvider
{
    public static class TinyDBConfigurationProviderExtensions
    {
        public static IConfigurationBuilder AddTinyDBConfiguration(this IConfigurationBuilder builder, TinyDBConfigOptions setup)
        {
            return builder.Add(new TinyDBConfigurationSource(setup));
        }

        public static IConfigurationBuilder AddTinyDBConfiguration(this IConfigurationBuilder builder,
            System.Func<System.Data.IDbConnection> createDbConnection, string tableName = "TinyDBConfig",
            bool reloadOnChange = false, System.TimeSpan? reloadInterval = null)
        {
            return builder.AddTinyDBConfiguration(new TinyDBConfigOptions
            {
                CreateDbConnection = createDbConnection,
                TableName = tableName,
                ReloadOnChange = reloadOnChange,
                ReloadInterval = reloadInterval
            });
        }
    }
}